#include<bits/stdc++.h>
using namespace std;
int n,b[4000006],m,f[1000006],ans=INT_MAX;
vector<int> g[1000006];
struct node{
	int s,id;
}a[4000006];
priority_queue<pair<int,int> > q;
int cmp(node x,node y){return x.s<y.s;}
signed main(){
	freopen("contest.in","r",stdin);
	freopen("contest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x; g[i].push_back(x);
		for(int j=1;j<=g[i][0];j++){
			cin>>b[j];
			a[++m].id=i; a[m].s=b[j];
		}
		sort(b+1,b+g[i][0]+1);
		int res=0;
		for(int j=1;j<=g[i][0];j++){
			if(b[j]==b[j-1] && j!=1) {res++;continue;}
			g[i].push_back(b[j]);
		}
		g[i][0]-=res;
	}
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=n;i++) q.push({g[i][1],i}),f[i]=1;
	for(int i=1;i<=m;i++){
		ans=min(ans,(q.top().first-a[i].s));
		f[a[i].id]++;
		if(f[a[i].id]>g[a[i].id][0]) break;
		q.push({g[a[i].id][f[a[i].id]],a[i].id});
		while(!q.empty()){
			int x=q.top().first, y=q.top().second;
			if(g[y][f[y]]!=x) q.pop();
			else break;
		}
	}
	cout<<ans;
	return 0;
}